package com.ymatou.iapi.wxtoken.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.wxtoken.parameter.NewGetTokenBean;
import com.ymatou.iapi.wxtoken.service.NewGetTokenCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.database.sqlwapper.WXToken2Wapper;
/**
*获取微信Token新通用接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_NewGetToken{
	private static NewGetTokenBean newgettokenBean;
	private static NewGetTokenCall newgettokenCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取微信Token新通用接口");
	}

	@Before
	public void caseUp() {
		newgettokenBean=new NewGetTokenBean();
		newgettokenCall=new NewGetTokenCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(newgettokenCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_NewGetToken_001() {
		Logger.start(true,"获取微信Token新通用接口,成功0-洋码头服务号");
		try {
			newgettokenBean.setAppType(0);
			newgettokenCall.setData(newgettokenBean);
			newgettokenCall.callService();			
			Logger.verifyEquals("200", newgettokenCall.getString("code"), "验证code");
			String token=newgettokenCall.getJsonObject().get("data").getAsJsonObject().get("token").getAsString();
			String dbtoken=new WXToken2Wapper().selectNewWxtokenByType(0, newgettokenBean.getAppType()).get(0).get("Token").toString();
			Logger.verifyEquals(token, dbtoken, "验证token");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_NewGetToken_002() {
		Logger.start(true,"获取微信Token新通用接口,成功1-全球优选");
		try {
			newgettokenBean.setAppType(1);
			newgettokenCall.setData(newgettokenBean);
			newgettokenCall.callService();			
			Logger.verifyEquals("200", newgettokenCall.getString("code"), "验证code");
			String token=newgettokenCall.getJsonObject().get("data").getAsJsonObject().get("token").getAsString();
			String dbtoken=new WXToken2Wapper().selectNewWxtokenByType(0, newgettokenBean.getAppType()).get(0).get("Token").toString();
			Logger.verifyEquals(token, dbtoken, "验证token");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_NewGetToken_003() {
		Logger.start(true,"获取微信Token新通用接口,成功2-代购神器商户端");
		try {
			newgettokenBean.setAppType(2);
			newgettokenCall.setData(newgettokenBean);
			newgettokenCall.callService();			
			Logger.verifyEquals("200", newgettokenCall.getString("code"), "验证code");
			String token=newgettokenCall.getJsonObject().get("data").getAsJsonObject().get("token").getAsString();
			String dbtoken=new WXToken2Wapper().selectNewWxtokenByType(0, newgettokenBean.getAppType()).get(0).get("Token").toString();
			Logger.verifyEquals(token, dbtoken, "验证token");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_NewGetToken_004() {
		Logger.start(true,"获取微信Token新通用接口,成功3代购神器买家端");
		try {
			newgettokenBean.setAppType(3);
			newgettokenCall.setData(newgettokenBean);
			newgettokenCall.callService();			
			Logger.verifyEquals("200", newgettokenCall.getString("code"), "验证code");
			String token=newgettokenCall.getJsonObject().get("data").getAsJsonObject().get("token").getAsString();
			String dbtoken=new WXToken2Wapper().selectNewWxtokenByType(0, newgettokenBean.getAppType()).get(0).get("Token").toString();
			Logger.verifyEquals(token, dbtoken, "验证token");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_NewGetToken_005() {
		Logger.start(true,"获取微信Token新通用接口,成功5独立小程序");
		try {
			newgettokenBean.setUserId(PayGateWayCallService.PayGdSq);
			newgettokenBean.setAppType(5);
			newgettokenCall.setData(newgettokenBean);
			newgettokenCall.callService();			
			Logger.verifyEquals("200", newgettokenCall.getString("code"), "验证code");
			String token=newgettokenCall.getJsonObject().get("data").getAsJsonObject().get("token").getAsString();
			String dbtoken=new WXToken2Wapper().selectNewWxtokenByTypeAndUid(0, newgettokenBean.getAppType(),newgettokenBean.getUserId()).get(0).get("Token").toString();
			Logger.verifyEquals(token, dbtoken, "验证token");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}